﻿﻿<html>
<head>
    <title>管理中心</title>
    <meta http-equiv="content-type" content="text/html; charset=UTF-8">

    <!-- ExtJS -->
    <link rel="stylesheet" type="text/css" href="../lib/ext/resources/css/ext-all-neptune.css"/>
    <script type="text/javascript" src="../lib/ext/ext-all.js"></script>
    <script type="text/javascript" src="../lib/gf/tree_common_grid.js"></script>
    <!-- GC -->

</head>

<body>

<script type="text/javascript">

    //引入Extjs所有类
    Ext.require(['*']);

    var parent_id = "0";

    Ext.onReady(function () {

        //弹出式描述功能初始化
        Ext.QuickTips.init();
        //使用cookie保存用户设置信息
        //Ext.state.Manager.setProvider(Ext.create('Ext.state.CookieProvider'));


        Ext.define('ResourceList', {
            extend: 'Ext.data.Model',
            fields: [
                '_id','res_code','res_name','url','http_method','type'
            ],
            idProperty: '_id'
        });

        // create the Data Store
        var store = Ext.create('Ext.data.Store', {
            id:'data_store',
            pageSize: 10,
            model: 'ResourceList',
            remoteSort: true,
            proxy: {
                type: 'ajax',
                url: '/res/list',
                reader: {
                    type: 'json',
                    root: 'data',
                    totalProperty: 'count'
                },
                simpleSortMode: true
            },
            sorters: [
                {
                    property: '_id'
                }
            ]
        });
        var grid = Ext.create('Ext.grid.Panel', {
            id:'my_grid',
            store: store,
            loadMask: true,
            region: 'center',
            selModel: Ext.create('Ext.selection.CheckboxModel'),
            columns: [
                {
                    text: "_id",
                    dataIndex: '_id',
                    hidden: true
                },
                {
                    text: '资源编码',
                    dataIndex: 'res_code',
                    width : 300

                },
                {
                    text: '资源名称',
                    dataIndex: 'res_name',
                    width : 200

                },{
                    text: '资源类型',
                    dataIndex: 'type',
                    width : 200,
                    renderer:function(value){
                        if(value=="operate"){
                            return "操作"
                        }else {
                            return "菜单"
                        }
                    }

                },
                {
                    text: '资源链接',
                    dataIndex: 'url',
                    width : 300

                },
                {
                    text: 'HTTP_METHOD',
                    dataIndex: 'http_method',
                    width : 300

                }
            ],
            // paging bar on the bottom
            bbar: Ext.create('Ext.PagingToolbar', {
                store: store,
                displayInfo: true,
                displayMsg: 'Displaying {0} - {1} of {2}',
                emptyMsg: "没有数据！！！"

            }),
            tbar: [
                {
                    pressed: true,
                    text: "修  改",
                    icon : '../img/edit.png',
                    handler: function(){doEdit(grid,"/admin/resource/add.html","修改资源",600,500)}
                },
                {
                    pressed: true,
                    icon : '../img/add.png',
                    text: "添  加",
                    handler: function(){add_res()}
                },
                {
                    pressed: true,
                    icon : '../img/delete.png',
                    text: "删  除",
                    handler: function(){doDel(grid,"/res/del",store)}
                }

            ]
        });


        //创建全景视图端
        var viewport = Ext.create('Ext.Viewport', {
            id: 'border-example',
            layout: 'border',//框式布局
            items: [

                 {
                    region: 'west',
                    stateId: 'navigation-panel',
                    id: 'west-panel',
                    border:false,
                    //title: '资源菜单',
                    // split: true,
                    width: 250,
                    collapsible: false,
                    margins: '0 0 0 5',
                    layout: 'fit',
                    html: '<iframe width="100%" height="100%" frameborder="0" src="tree1.html"></iframe>'
                },grid
               ]
        });


        // trigger the data store load
        store.loadPage(1);
        window.refresh = function(){
            //store.loadPage(1);
            store.loadPage(1,{params:{"parent_id":parent_id}});
        }

        window.closeWin = function(){
            win.hide();
        }

        function load_data(pid) {
            this.parent_id = pid;
            store.loadPage(1,{params:{"parent_id":pid}});
        }

        function add_res(){
            doAdd("/admin/resource/add.html?parent_id="+this.parent_id,"新建资源",600,500)
        }

    });

</script>
</body>
</html>